package net.zoneland.knowledge.utils;

import java.util.Optional;
import java.util.regex.Pattern;

/**
 * 日志辅助工具.
 * @author bcc
 */
public final class LoggerHelper {

    /**
     * 换行字符.
     */
    private static final Pattern PATTERN_BREAKING = Pattern.compile("[\n\r\t]");

    private LoggerHelper() {
    }

    /**
     * Replace pattern-breaking characters.
     * @param str 字符串
     * @return 替换后的字段串
     */
    public static String replaceBreakCharacters(final String str) {
        return Optional.ofNullable(str)
                .map(s -> PATTERN_BREAKING.matcher(s).replaceAll("_"))
                .orElse(null);
    }

}
